package com.example.studyBean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Component
public class TestBean implements ApplicationRunner, DisposableBean, ApplicationListener<ContextRefreshedEvent> {

    private final Logger log = LoggerFactory.getLogger(TestBean.class);


    public TestBean() {
        log.error("步骤1：实例化bean");
    }

    @Override
    public void destroy() throws Exception {
        log.error("步骤5：销毁bean");
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.error("步骤3：初始化bean");
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        log.error("步骤4:初始化完成后调用方法");
    }
}
